layui.config({
    base: "/js/modules/"
}).extend({
    "listView": "listView"
});
layui.use(['form', 'listView', 'laydate', 'jquery', 'common', 'table'], function () {
    let layDate = layui.laydate,
        form = layui.form,
        common = layui.common,
        layer = layui.layer,
        table = layui.table,
        $ = layui.$;

    layDate.render(
        {
            elem: "#beginTime", trigger: 'click', type: 'datetime'
        }
    );
    layDate.render(
        {
            elem: "#endTime", trigger: 'click', type: 'datetime'
        }
    );

    layui.listView.tableInit({
        id: 'deviceInfo',
        url: '/device/info/page',
        page: true,
        cols: [
            {field: 'number', title: '序号', fixed: 'true', type: 'numbers'},
            {field: 'typeName', title: '类型'},
            {field: 'name', title: '名称'},
            {field: 'no', title: '编号'},
            {field: 'location', title: '位置'},
            {
                field: 'warnStatus', title: '告警状态', templet: function (d) {
                    if (d.warnStatus == '0') {
                        return '<span style="color:darkseagreen">未告警</span>'
                    } else {
                        return '<span style="color:red">告警中</span>'

                    }
                }
            },
            {
                field: 'online', title: '是否在线', templet: function (d) {
                    if (d.online) {
                        return '<span style="color:darkseagreen">在线</span>';
                    } else {
                        return '<span style="color:red">离线</span>';

                    }
                }
            }
            // ,
            // {
            //     field: 'prevNodeName', title: '前一节点', templet: function (d) {
            //         if (d.prevNodeName == 'undefined' || d.prevNodeName == null) {
            //             return "";
            //         }
            //         return d.prevNodeName + "(" + d.prevNodeId + ")";
            //     }
            // },
            // {
            //     field: 'nextNodeName', title: '后一节点', templet: function (d) {
            //         if (d.nextNodeName == 'undefined' || d.nextNodeName == null) {
            //             return "";
            //         }
            //         return d.nextNodeName + "(" + d.nextNodeId + ")";
            //     }
            // }
            ,
            {fixed: 'right', title: '操作', toolbar: '#barDemo', width: 150}
        ]
    });

    $('#add').on('click', function () {
        layer.open({
            title: '新增设备信息',
            type: 2,
            area: ['400px', '500px'],
            fixed: false, //不固定
            maxmin: true,
            content: '/device/info/toAddDeviceInfo'
        });
    });


    //操作
    table.on('tool(deviceInfo)', function (obj) {
        var data = obj.data;
        // console.log(obj.data)
        if (obj.event === 'edit') {
            // layer.alert('编辑行：<br>'+ JSON.stringify(data))
            layer.open({
                title: '编辑设备信息',
                type: 2,
                area: ['400px', '500px'],
                fixed: false, //不固定
                maxmin: true,
                content: '/device/info/queryDeviceInfo?id=' + data.id
            });
        }
    });

});
